// timer => IO => idle => poll  => check => close
const Redis = require("ioredis");
const RedisLock = require("./redis");
const redis1 = new Redis(6379, "127.0.0.1");
const redis2 = new Redis(6379, "127.0.0.1");
const uuidv1 = require("uuid/v1");
const redisLock = new RedisLock(redis1);
const sleep = require("./utils");

async function test(key) {
  try {
    const id = uuidv1();
    await redisLock.lock(key, id, 20);
    await sleep(3000);
    // const unLock = await redisLock.unLock(key, id);
    // console.log("unLock: ", key, id, unLock);
    redis2.set("name1", 2);
  } catch (err) {
    console.log("上锁失败", err);
  }
}

test("name1");
// test("name1");
